package algorithm;

import java.util.Random;

public class leetcode_0384 {
    private int[] nums;
    private Random random;

//    public Solution(int[] nums) {
//        this.nums = nums;
//        random = new Random();
//    }

    //重置数组，就是返回之前的数组
    public int[] reset() {
        return nums;
    }


    //打乱数组
    public int[] shuffle() {
        if (nums == null)
            return null;
        int[] a = nums.clone();//clone一个新的数组
        for (int j = 1; j < a.length; j++) {
            int i = random.nextInt(j + 1);
            swap(a, i, j);
        }
        return a;
    }

    //交换两个数字的值
//        private void swap(int[] a, int i, int j) {
//            if (i != j) {
//                a[i] ^= a[j];
//                a[j] ^= a[i];
//                a[i] ^= a[j];
//            }
//        }

    private void swap(int[] a, int i, int j) {
        if (i != j) {
            a[i] = a[i] + a[j];
            a[j] = a[i] - a[j];
            a[i] = a[i] - a[j];
        }
    }


}
